package com.bytefy.core;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;


public class WaitQuit {
	private Map<String, ICallback<String>> callbacks = new HashMap<String, ICallback<String>>();

	public void addCallback(String cmd, ICallback<String> callback) {
		callbacks.put(cmd, callback);
	}

	public void loop() {
		Scanner s = new Scanner(System.in);
		System.out.print("\r\nbytefy> ");
		while (s.hasNextLine()) {
			String cmd = s.nextLine().trim();
			boolean finded = false;
			if (!cmd.isEmpty()) {
				System.out.println("Typed: '" + cmd + "'");
				for (String name : callbacks.keySet()) {
					if (!name.equals(cmd))
						continue;
					callbacks.get(name).call(name);
					finded = true;
					break;
				}
				if (!finded)
					System.out.println("Error: unknown command");
			}
			System.out.print("\r\nbytefy> ");
		}
	}
}
